package com.acme.chat.util;

import java.util.LinkedList;
import java.util.List;

import com.acme.chat.message.PrivateMessage;

public class BlockingQueue {

    private final List<PrivateMessage> queue = new LinkedList<PrivateMessage>();

    public void offer(final PrivateMessage message) {
        synchronized (queue) {
            queue.add(message);
            queue.notifyAll();
        }
    }

    public PrivateMessage poll() throws InterruptedException {
        synchronized (queue) {
            while (queue.isEmpty()) {
                queue.wait();
            }
            return queue.remove(0);
        }
    }
}
